#!/usr/bin/env bash

IMAGE_NAME="material_identification"
IMAGE_VERSION="v1.3"
CONTAINER_NAME="material_identification"
HOST_PORT="8122"
CONTAINER_PORT='5000'
PORT_MAPPING="${HOST_PORT}:${CONTAINER_PORT}"            # 主机端口:容器端口

# 环境变量   DEVTEST  ， 线上环境   PRODUCT
CONFIG_ENV="DEVTEST"
# 并行工作进程数
GUNICORN_WORKERS=4
# 指定每个工作者的线程数
GUNICORN_THREADS=8
# 监听内网端口5000
GUNICORN_BIND=${CONTAINER_PORT}
# 设置最大并发量
GUNICORN_WORKER_CONNECTIONS=2000
# 设置超时时间120s，默认为30s
GUNICORN_TIMEOUT=30

ENVS="-e CONFIG_ENV=${CONFIG_ENV}
      -e GUNICORN_WORKERS=${GUNICORN_WORKERS}
      -e GUNICORN_THREADS=${GUNICORN_THREADS}
      -e GUNICORN_WORKER_CONNECTIONS=${GUNICORN_WORKER_CONNECTIONS}
      -e GUNICORN_TIMEOUT=${GUNICORN_TIMEOUT}"

# 停止并删除原容器
docker stop ${CONTAINER_NAME}
docker rm ${CONTAINER_NAME}

# 构造镜像
docker build -t ${IMAGE_NAME}:${IMAGE_VERSION} .

# 实例化容器
docker run ${ENVS} --name ${CONTAINER_NAME} -p ${PORT_MAPPING} -idt ${IMAGE_NAME}:${IMAGE_VERSION}
